home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / uupc11yt.zip / UTIL / COMM34.C next >
C/C++ Source or Header  |  1993-04-10  |  6KB  |  192 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    c o m m 3 4 . c                                                 */
  3. /*                                                                    */
  4. /*    Set/report communications port addresses                        */
  5. /*                                                                    */
  6. /*    Modified to report addresses and report usage by Andrew H.      */
  7. /*    Derbyshire.  Changes Copyright (c) 1992, Andrew H.              */
  8. /*    Derbyshire.                                                     */
  9. /*--------------------------------------------------------------------*/
  10.  
  11. /*--------------------------------------------------------------------*/
  12. /*                          RCS Information                           */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*
  16.  *    $Id: COMM34.C 1.2 1993/04/11 00:33:54 ahd Exp $
  17.  *
  18.  *    Revision history:
  19.  *    $Log: COMM34.C $
  20.  * Revision 1.2  1993/04/11  00:33:54  ahd
  21.  * Global edits for year, TEXT, etc.
  22.  *
  23.  * Revision 1.1  1992/11/15  04:29:22  ahd
  24.  * Initial revision
  25.  *
  26.  * Revision 1.2  1992/04/27  00:38:58  ahd
  27.  * Add RCS header
  28.  *
  29.  */
  30.  
  31. static char rcsid[] = "$Id: COMM34.C 1.2 1993/04/11 00:33:54 ahd Exp $";
  32.  
  33. /*
  34.  * Compiler: Microsoft C 5.1
  35.  *
  36.  * COM34.C - set COM3 - COM4 addresses
  37.  *
  38.  * This program inserts the addresses specified by argv[1] - argv[2]
  39.  * into the BIOS table at 0040:0004 (COM3 - COM4)
  40.  *
  41.  * Usage: COMM4 xxx yyy
  42.  * where  xxx is COM3 address (hex), yyy is COM4 address (hex)
  43.  */
  44.  
  45. /*--------------------------------------------------------------------*/
  46. /*                      C standard include files                      */
  47. /*--------------------------------------------------------------------*/
  48.  
  49. #include <stdio.h>
  50. #include <stdlib.h>
  51.  
  52. /*--------------------------------------------------------------------*/
  53. /*                    UUPC/extended include files                     */
  54. /*--------------------------------------------------------------------*/
  55.  
  56. #include "lib.h"
  57. #include "timestmp.h"
  58.  
  59. #define MK_FP(seg,ofs)  ((void far *)(((unsigned long)(seg) << 16) | (ofs)))
  60.  
  61. static struct addr far *ports = (struct addr far *) MK_FP(0x40, 0);
  62.  
  63. unsigned htoi( char * buf );
  64. static void status( void );
  65. static void usage( void );
  66.  
  67. struct addr
  68. {
  69.    unsigned com[4];
  70. };
  71.  
  72. /*--------------------------------------------------------------------*/
  73. /*    m a i n                                                         */
  74. /*                                                                    */
  75. /*    Main program                                                    */
  76. /*--------------------------------------------------------------------*/
  77.  
  78. void main(int argc, char **argv)
  79. {
  80.    unsigned htoi();
  81.  
  82. /*--------------------------------------------------------------------*/
  83. /*                        Report our parentage                        */
  84. /*--------------------------------------------------------------------*/
  85.  
  86.    banner( argv );
  87.  
  88.    switch( argc )
  89.    {
  90.       case 3:
  91.          ports->com[3] = htoi(argv[2]);
  92.  
  93.       case 2:
  94.          ports->com[2] = htoi(argv[1]);
  95.          break;
  96.  
  97.       default:
  98.          usage();
  99.    }
  100.  
  101. /*--------------------------------------------------------------------*/
  102. /*                     Report new status and exit                     */
  103. /*--------------------------------------------------------------------*/
  104.  
  105.    status();
  106.    exit( 0 );
  107.  
  108. } /* main */
  109.  
  110. /*--------------------------------------------------------------------*/
  111. /*    s t a t u s                                                     */
  112. /*                                                                    */
  113. /*    Report current serial port status                               */
  114. /*--------------------------------------------------------------------*/
  115.  
  116. static void status( void )
  117. {
  118.    int port = 0;
  119.  
  120.    printf("Communications ports: ");
  121.  
  122.    while( port < 4 )
  123.    {
  124.       if (port)
  125.          printf(", ");
  126.  
  127.       if (ports->com[port])
  128.          printf("COM%d = %x",port+1, ports->com[port] );
  129.       else
  130.          printf("COM%d = (none)",port+1);
  131.  
  132.       port++;
  133.    } /* while */
  134.  
  135.    putchar('\n');
  136.  
  137. } /* status */
  138.  
  139. /*--------------------------------------------------------------------*/
  140. /*    h t o i                                                         */
  141. /*                                                                    */
  142. /*    Convert printable hex to integer                                */
  143. /*--------------------------------------------------------------------*/
  144.  
  145. unsigned htoi(char *buf)
  146. {
  147.    unsigned sum;
  148.    char c;
  149.  
  150.    for (sum = 0; (c = *buf) != '\0'; buf++)
  151.    {
  152.       if ((c >= 'a') && (c <= 'f'))
  153.          c = c - 'a' + 'A';
  154.  
  155.       if ((c >= 'A') && (c <= 'F'))
  156.          sum = (sum * 16) + (c - 'A' + 10);
  157.  
  158.       else if ((c >= '0') && (c <= '9'))
  159.          sum = (sum * 16) + (c - '0');
  160.  
  161.       else
  162.       {
  163.          printf("Invalid port address %s, program exiting.\n",buf);
  164.          usage();
  165.       }
  166.    }
  167.    return(sum);
  168.  
  169. } /* htoi */
  170.  
  171. /*--------------------------------------------------------------------*/
  172. /*    u s a g e                                                       */
  173. /*                                                                    */
  174. /*    Report program usage                                            */
  175. /*--------------------------------------------------------------------*/
  176.  
  177. static void usage( void )
  178. {
  179.    printf(
  180.       "This program alters the BIOS information for COM ports 3 and 4 for\n"
  181.       "use by UUPC/extended, MS-Kermit and other programs, and reports the\n"
  182.       "addresses of all installed COM ports.  Usage:\n\n"
  183.       "\tCOMM34\taddr3 [addr4]\n\n"
  184.       "Where addr3 is the hexadecimal address for port 3 (usually 2E8) and\n"
  185.       "Where addr4 is the optional hexadecimal address for port 4 (usually\n"
  186.       "2E0).\n\n");
  187.  
  188.    status();
  189.  
  190.    exit(1);
  191. }
  192.